| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var assert = require('chai').assert, |
||
| 4 | describe('SourceReference', function(){ |
||
| 5 | |||
| 6 | it('Create with JSON', function(){ |
||
| 7 | var ref = GedcomX.SourceReference({ |
||
| 8 | id: 'source-ref', |
||
| 9 | description: 'http://some/uri', |
||
| 10 | attribution: { |
||
| 11 | created: 11121211112 |
||
| 12 | }, |
||
| 13 | qualifiers: [ |
||
| 14 | { |
||
| 15 | name: 'http://gedcomx.org/CharacterRegion', |
||
| 16 | value: '37' |
||
| 17 | } |
||
| 18 | ] |
||
| 19 | }); |
||
| 20 | assert.equal(ref.getId(), 'source-ref'); |
||
| 21 | assert.equal(ref.getDescription(), 'http://some/uri'); |
||
| 22 | assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); |
||
| 23 | assert.equal(ref.getQualifiers().length, 1); |
||
| 24 | assert.equal(ref.getQualifiers()[0].getName(), 'http://gedcomx.org/CharacterRegion'); |
||
| 25 | }); |
||
| 26 | |||
| 27 | it('Build', function(){ |
||
| 28 | var ref = GedcomX.SourceReference() |
||
| 29 | .setId('source-ref') |
||
| 30 | .setDescription('http://some/uri') |
||
| 31 | .setAttribution({ created: 11121211112 }) |
||
| 32 | .addQualifier( |
||
| 33 | GedcomX.Qualifier().setName('http://gedcomx.org/CharacterRegion').setValue(37) |
||
| 34 | ); |
||
| 35 | assert.equal(ref.getId(), 'source-ref'); |
||
| 36 | assert.equal(ref.getDescription(), 'http://some/uri'); |
||
| 37 | assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); |
||
| 38 | assert.equal(ref.getQualifiers().length, 1); |
||
| 39 | assert.equal(ref.getQualifiers()[0].getName(), 'http://gedcomx.org/CharacterRegion'); |
||
| 40 | }); |
||
| 41 | |||
| 42 | it('toJSON', function(){ |
||
| 43 | var refData = { |
||
| 44 | id: 'source-ref', |
||
| 45 | description: 'http://some/uri', |
||
| 46 | attribution: { |
||
| 47 | created: 11121211112 |
||
| 48 | }, |
||
| 49 | qualifiers: [ |
||
| 50 | { |
||
| 51 | name: 'http://gedcomx.org/CharacterRegion', |
||
| 52 | value: '37' |
||
| 53 | } |
||
| 54 | ] |
||
| 55 | }, |
||
| 56 | ref = GedcomX.SourceReference(refData); |
||
| 57 | assert.deepEqual(ref.toJSON(), refData); |
||
| 58 | }); |
||
| 59 | |||
| 60 | }); |